$(document).ready(function() {
    if (typeof document.getElementById("regform") != undefined && document.getElementById("regform") != null) {
        document.getElementById("regbutton").disabled = true;
        document.getElementById("regpass").disabled = true;
        document.getElementById("regpass2").disabled = true;
        document.getElementById("regemail").disabled = true;
    }
    if (typeof document.getElementById("edit") != undefined && document.getElementById("edit") != null) {
        document.getElementById("edit_button").disabled = true;
        document.getElementById("edit_button").className = "inactive";
    }
    $("#sugo").hide();
    $("#eredmeny").hide();
    if ($.cookie("open") == 1) {
        $("#hozzaszolas").css("display", "block");
        $.cookie("open", null);
    }
}
);

function user_tovabb() {
    if (!document.getElementById("user_success")) {
        document.getElementById("regpass").disabled = true;
    }
    else {
        document.getElementById("regpass").disabled = false;
    }
}

function pass_tovabb() {
    if (!document.getElementById("passw_success")) {
        document.getElementById("regpass2").disabled = true;
    }
    else {
        document.getElementById("regpass2").disabled = false;
    }
}

function email_tovabb() {
    if (!document.getElementById("passw2_success")) {
        document.getElementById("regemail").disabled = true;
    }
    else {
        document.getElementById("regemail").disabled = false;
    }
}

function reg_ok() {
    if (!document.getElementById("user_success") ||
            !document.getElementById("passw_success") ||
            !document.getElementById("passw2_success") ||
            !document.getElementById("email_success")) {
        document.getElementById("regbutton").disabled = true;
    }
    else {
        document.getElementById("regbutton").disabled = false;
    }
}
function finishAjax(id, response) {
    $('#' + id).html(unescape(response));
    $('#' + id).fadeIn(1000);
}

function validate_username() {
    var username = $("#regname").val();
    if (username.length >= 0) {
        $.post("validate_username.php",
                {
                    regusername: $("#regname").val()
                },
        function(response) {
            $("#validation_info").fadeOut();
            setTimeout("finishAjax('validation_info', '" + escape(response) + "')", 450);
        }
        );
    }
    setTimeout("user_tovabb(); document.getElementById('regpass').focus()", 1500);
    setTimeout("reg_ok()", 1500);
}

function validate_password() {
    var passw = $("#regpass").val();
    if (passw.length >= 0) {
        $.post("validate_password.php",
                {
                    regpass: $("#regpass").val()
                },
        function(response) {
            $("#password_validation").fadeOut();
            setTimeout("finishAjax('password_validation', '" + escape(response) + "')", 450);
        }
        );
    }
    setTimeout("pass_tovabb(); document.getElementById('regpass2').focus()", 1500);
    setTimeout("reg_ok()", 1500);
}

function check_password() {
    var passw2 = $("#regpass2").val();
    if (passw2.length >= 0) {
        $.post("check_password.php",
                {
                    regpass1: $("#regpass").val(),
                    regpass2: $("#regpass2").val()
                },
        function(response) {
            $("#password_validation2").fadeOut();
            setTimeout("finishAjax('password_validation2', '" + escape(response) + "')", 450);
        }
        );
    }
    setTimeout("email_tovabb(); document.getElementById('regemail').focus()", 1500);
    setTimeout("reg_ok()", 1500);
}

function validate_email() {
    var email = $("#regemail").val();
    if (email.length >= 0) {
        $.post("validate_email.php",
                {
                    regemail: $("#regemail").val()
                },
        function(response) {
            $("#email_validation").fadeOut();
            setTimeout("finishAjax('email_validation', '" + escape(response) + "')", 450);
        }
        );
    }
    setTimeout("reg_ok()", 1500);
}

function sugo() {
    var ertek = $("#hol").val();
    switch (ertek) {
        case "director":
            $("#sugo").show();
            document.getElementById("sugo").innerHTML = "A rendező filmjeit adja eredményül";
            break;
        case "cast":
            $("#sugo").show();
            document.getElementById("sugo").innerHTML = "A színész filmjeit adja eredményül";
            break;
        default:
            $("#sugo").hide();
            break;
    }
}

function add() {
    $("#new_up").append('<tr><td><input type="text" name="actor[]"/></td><td>-</td><td><input type="text" name="role[]"/></td></tr>');
}

function no_upload() {
    if (!document.getElementById("van")) {
        document.getElementById("upload_button").disabled = false;
    }
    else {
        document.getElementById("upload_button").disabled = true;
    }
}
function validate_file() {
    var file = document.getElementById("file").files[0];
    if (file.name.length > 0) {
        $.post("validate_file.php",
                {
                    filename: file.name
                },
        function(response) {
            $("#exist").fadeOut();
            setTimeout("finishAjax('exist', '" + escape(response) + "')", 450);
        });
    }
    setTimeout("no_upload()", 1500);
    var tomb = new Array("jpg", "jpeg", "JPG", "JPEG");
    var ext = file.name.split(".")[1];
    if (file.size > 51200 && tomb.indexOf(ext) == -1) {
        document.getElementById("keret").innerHTML = "Maximális feltölthető méret 50Kb!<br>Csak .jpg és .jpeg kiterjesztésű képet lehet feltölteni!";
        $("#keret").show();
        document.getElementById("upload_button").disabled = true;
    }
    else if (file.size > 51200 && tomb.indexOf(ext) != -1) {
        document.getElementById("keret").innerHTML = "Maximális feltölthető méret 50Kb!";
        $("#keret").show();
        document.getElementById("upload_button").disabled = true;
    }
    else if (file.size <= 51200 && tomb.indexOf(ext) == -1) {
        document.getElementById("keret").innerHTML = "Csak .jpg és .jpeg kiterjesztésű képet lehet feltölteni!";
        $("#keret").show();
        document.getElementById("upload_button").disabled = true;
    }
    else if (file.size <= 51200 && tomb.indexOf(ext) != -1) {
        $("#keret").hide();
        document.getElementById("upload_button").disabled = false;
    }
}

function edit_ok() {
    if (!document.getElementById("passw2_success") && document.getElementById("email_success")) {
        if (document.getElementById("passw2_error")) {
            if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            }
        } else {
            if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else {
                document.getElementById("edit_button").disabled = false;
                document.getElementById("edit_button").className = "";
            }
        }
    } else if (document.getElementById("passw2_success") && !document.getElementById("email_success")) {
        if (document.getElementById("email_error")) {
            if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            }
        } else {
            if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else {
                document.getElementById("edit_button").disabled = false;
                document.getElementById("edit_button").className = "";
            }
        }
    } else if (!document.getElementById("passw2_success") && !document.getElementById("email_success")) {
        if (document.getElementById("passw2_error") && document.getElementById("email_error")) {
            if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            }
        } else if (document.getElementById("passw2_error")) {
            if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            }
        } else if (document.getElementById("email_error")) {
            if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML != "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML == "") {
                document.getElementById("edit_button").disabled = true;
                document.getElementById("edit_button").className = "inactive";
            }
        }
    } else {
        if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML != "") {
            document.getElementById("edit_button").disabled = true;
            document.getElementById("edit_button").className = "inactive";
        } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML != "") {
            document.getElementById("edit_button").disabled = true;
            document.getElementById("edit_button").className = "inactive";
        } else if (document.getElementById("keret").innerHTML != "" && document.getElementById("exist").innerHTML == "") {
            document.getElementById("edit_button").disabled = true;
            document.getElementById("edit_button").className = "inactive";
        } else if (document.getElementById("keret").innerHTML == "" && document.getElementById("exist").innerHTML == "") {
            document.getElementById("edit_button").disabled = false;
            document.getElementById("edit_button").className = "";
        }
    }
}

function validate_edit_email() {
    var email = $("#edit_email").val();
    if (email.length >= 0) {
        $.post("validate_email.php",
                {
                    regemail: email
                },
        function(response) {
            $("#email_validation").fadeOut();
            setTimeout("finishAjax('email_validation', '" + escape(response) + "')", 450);
        }
        );
    }
    setTimeout("edit_ok()", 1500);
}

function validate_edit_pass() {
    var passw1 = document.getElementsByName("edit_pass").item(0).value;
    var passw2 = document.getElementsByName("edit_pass2").item(0).value;
    if (passw2.length >= 0) {
        $.post("check_password.php",
                {
                    regpass1: passw1,
                    regpass2: passw2
                },
        function(response) {
            $("#password_validation2").fadeOut();
            setTimeout("finishAjax('password_validation2', '" + escape(response) + "')", 450);
        }
        );
    }
    setTimeout("edit_ok()", 1500);
}

function validate_avatar() {
    var file = document.getElementById("file").files[0];
    if (file.name.length > 0) {
        $.post("validate_avatar.php",
                {
                    filename: file.name
                },
        function(response) {
            $("#exist").fadeOut();
            setTimeout("finishAjax('exist', '" + escape(response) + "')", 450);
        });
    }
    var tomb = new Array("jpg", "jpeg", "JPG", "JPEG", "gif", "GIF");
    var ext = file.name.split(".")[1];
    if (file.size > 51200 && tomb.indexOf(ext) == -1) {
        document.getElementById("keret").innerHTML = "Maximális feltölthető méret 50Kb!<br>Csak .jpg .jpeg és .gif kiterjesztésű képet lehet feltölteni!";
        $("#keret").show();
        document.getElementById("edit_button").disabled = true;
    }
    else if (file.size > 51200 && tomb.indexOf(ext) != -1) {
        document.getElementById("keret").innerHTML = "Maximális feltölthető méret 50Kb!";
        $("#keret").show();
        document.getElementById("edit_button").disabled = true;
    }
    else if (file.size <= 51200 && tomb.indexOf(ext) == -1) {
        document.getElementById("keret").innerHTML = "Csak .jpg .jpeg .gif kiterjesztésű képet lehet feltölteni!";
        $("#keret").show();
        document.getElementById("edit_button").disabled = true;
    }
    else if (file.size <= 51200 && tomb.indexOf(ext) != -1) {
        $("#keret").hide();
        document.getElementById("edit_button").disabled = false;
    }
}

function lenyit(id) {
    if ($(".wrapper").hasClass('active')) {
        $(".tools2").slideUp(500);
        $(".tools2").html("");
        $(".wrapper").removeClass('active').animate({
            left: -$(".wrapper").width()
        }, 500);
        $(".data:visible").slideUp(500);
    } else {
        $(".tools2").html("");
        $(".data:visible").slideUp(500);
    }
    if ($("#data" + id).is(":hidden")) {
        $("#data" + id).slideDown(500);
        var b = $(".username").eq(id).attr("id");
        $.post("user_comment_list.php",
                {
                    username: b
                }, function(result) {
            $(".tools2").html(result);
        });
    } else {
        if ($(".wrapper").hasClass('active')) {
            $(".tools2").slideUp(500);
            $(".tools2").html("");
            $(".wrapper").removeClass('active').animate({
                left: -$(".tools").width()
            }, 500);
            $("#data" + id).slideUp(500);
        } else {
            $("#data" + id).slideUp(500);
        }
    }
}

function kinyit(id) {
    var position = $("#" + id).position();
    var pos = $(".wrapper").position();
    var a = position.top - pos.top;
    if (a < 0) {
        a *= -1;
    }
    var animIn = function() {
        $(".wrapper").css("margin-top", a);
        $(".wrapper").addClass('active').show().css({
            left: -($(".wrapper").width())
        }).animate({
            left: 0
        }, 500);
    }
    if ($(".wrapper").hasClass('active')) {
        $(".tools2").slideUp(500);
        $(".wrapper").removeClass('active').animate({
            left: -$(".wrapper").width()
        }, 500);
    } else if (!$(".wrapper").hasClass('active')) {
        animIn();
    }
}

function user_comments() {
    var c = $(".tools").outerHeight();
    $(".tools2").position.top += c;
    if ($(".tools2").is(":hidden")) {
        $(".tools2").slideDown(500);
    } else {
        $(".tools2").slideUp(500);
    }
}

function comment_show() {
    if ($("#hozzaszolasok").html() == "Hozzászólások megjelenítése") {
        $("#hozzaszolas").slideDown(500);
        $("#hozzaszolasok").html("Hozzászólások elrejtése");
    } else {
        $("#hozzaszolas").slideUp(500);
        $("#hozzaszolasok").html("Hozzászólások megjelenítése");
    }
}

function show_comment_box() {
    if ($("#b").is(":hidden")) {
        $("#b").slideDown(500);
        document.getElementById("b").scrollIntoView(true);
    } else {
        $("#b").slideUp(500);
    }
}

function add_comment() {
    var a = $("#textarea").val();
    var b = window.location.href.split("id=")[1];
    var c = $(".uname").attr("id");
    $.post("add_comment.php", {
        content: a,
        id: b,
        username: c
    });
    $.cookie("open", 1);
    setTimeout("document.location.reload(true)", 1000);
}

function delete_comment(valami) {
    var a = $("#" + valami).attr("id");
    $.post("delete_comment.php", {
        azon: a
    }, function(data) {
        $("#" + valami).slideUp(100);
        $("#" + valami).html(data);
        $("#" + valami).css("color", "#669933");
        $("#" + valami).slideDown(100);
    });
}

function bann(valami) {
    var a = $(".data:visible").attr("id").split("ta")[1];
    var b = $(".username").eq(a).attr("id");
    $.post("bann_user.php", {
        username: b,
        mod: valami
    }, function(data) {
        $(".data:visible").children("#status").html(data);
        if (data == "bannolva") {
            $(".data:visible").children("#status").css("background-color", "red");
        } else if (data == "offline") {
            $(".data:visible").children("#status").css("background-color", "#669933");
        }
    });
}

function check() {
    if ($("#sender_name").val() == "") {
        $("#sender_name").css("border", "1px solid red");
        return false;
    } else {
        $("#sender_name").css("border", "none");
    }
    if ($("#sent_from").val() == "") {
        $("#sent_from").css("border", "1px solid red");
        return false;
    } else {
        $("#sent_from").css("border", "none");
    }
    if ($("#subject").val() == "") {
        $("#subject").css("border", "1px solid red");
        return false;
    } else {
        $("#subject").css("border", "none");
    }
    if ($("#message").val() == "") {
        $("#message").css("border", "1px solid red");
        return false;
    } else {
        $("#message").css("border", "none");
    }
}